// Service worker file. Renders as serviceworker.js
// This is now a self-destructing service worker. See https://github.com/NekR/self-destroying-sw

<% unless Rails.env.test? %>
  self.addEventListener('install', function(e) {
    self.skipWaiting();
  });

  self.addEventListener('activate', function(e) {
    self.registration.unregister()
      .then(function() {
        return self.clients.matchAll();
      })
      .then(function(clients) {
        clients.forEach(client => {
          // Check if client.navigate is supported before running it.
          client.navigate && client.navigate(client.url);
        })
      });
  });
<% end %>
